{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Moving Stones Until Consecutive"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #brainteaser #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #脑筋急转弯 #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: numMovesStones"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #移动石子直到连续"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>三枚石子放置在数轴上，位置分别为 <code>a</code>，<code>b</code>，<code>c</code>。</p>\n",
    "\n",
    "<p>每一回合，你可以从两端之一拿起一枚石子（位置最大或最小），并将其放入两端之间的任一空闲位置。形式上，假设这三枚石子当前分别位于位置 <code>x, y, z</code> 且 <code>x < y < z</code>。那么就可以从位置 <code>x</code> 或者是位置 <code>z</code> 拿起一枚石子，并将该石子移动到某一整数位置 <code>k</code> 处，其中 <code>x < k < z</code> 且 <code>k != y</code>。</p>\n",
    "\n",
    "<p>当你无法进行任何移动时，即，这些石子的位置连续时，游戏结束。</p>\n",
    "\n",
    "<p>要使游戏结束，你可以执行的最小和最大移动次数分别是多少？ 以长度为 2 的数组形式返回答案：<code>answer = [minimum_moves, maximum_moves]</code></p>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>a = 1, b = 2, c = 5\n",
    "<strong>输出：</strong>[1, 2]\n",
    "<strong>解释：</strong>将石子从 5 移动到 4 再移动到 3，或者我们可以直接将石子移动到 3。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>a = 4, b = 3, c = 2\n",
    "<strong>输出：</strong>[0, 0]\n",
    "<strong>解释：</strong>我们无法进行任何移动。\n",
    "</pre>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ol>\n",
    "\t<li><code>1 <= a <= 100</code></li>\n",
    "\t<li><code>1 <= b <= 100</code></li>\n",
    "\t<li><code>1 <= c <= 100</code></li>\n",
    "\t<li><code>a != b, b != c, c != a</code></li>\n",
    "</ol>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [moving-stones-until-consecutive](https://leetcode.cn/problems/moving-stones-until-consecutive/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [moving-stones-until-consecutive](https://leetcode.cn/problems/moving-stones-until-consecutive/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['1\\n2\\n5', '4\\n3\\n2', '3\\n5\\n1']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        stones.sort()\n",
    "        n = len(stones)\n",
    "        e1 = stones[-2] - stones[0] - n + 2\n",
    "        e2 = stones[-1] - stones[1] - n + 2\n",
    "        max_move = max(e1, e2)\n",
    "        if e1 == 0 or e2 == 0:\n",
    "            return [min(2, max_move), max_move]\n",
    "        max_cnt = left = 0\n",
    "        for right, sr in enumerate(stones):\n",
    "            while sr - stones[left] + 1 > n:\n",
    "                left += 1\n",
    "            max_cnt = max(max_cnt, right - left + 1)\n",
    "        return [n - max_cnt, max_move]        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        stones.sort()\n",
    "        n = len(stones)\n",
    "        a = stones[-2] - stones[0] - n + 2\n",
    "        b = stones[-1] - stones[1] - n + 2\n",
    "        ma = max(a, b)\n",
    "        if a == 0 or b == 0:\n",
    "            return [min(2, ma), ma]\n",
    "        \n",
    "        maxcnt = l = 0\n",
    "        for r, stone in enumerate(stones):\n",
    "            while stone - stones[l] + 1 > n:\n",
    "                l += 1\n",
    "            maxcnt = max(maxcnt, r - l + 1)\n",
    "        \n",
    "        return [n - maxcnt, ma]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    # # 下跳棋\n",
    "    # https://leetcode.cn/problems/moving-stones-until-consecutive-ii/solutions/2212638/tu-jie-xia-tiao-qi-pythonjavacgo-by-endl-r1eb/\n",
    "    def numMovesStonesII(self, s: List[int]) -> List[int]:\n",
    "        s.sort()\n",
    "        n = len(s)\n",
    "        e1 = s[-2] - s[0] - n + 2\n",
    "        e2 = s[-1] - s[1] - n + 2  # 计算空位\n",
    "        max_move = max(e1, e2)\n",
    "        if e1 == 0 or e2 == 0:  # 特殊情况：没有空位\n",
    "            return [min(2, max_move), max_move]\n",
    "\n",
    "        max_cnt = left = 0\n",
    "        for right, sr in enumerate(s):  # 滑动窗口：枚举右端点所在石子\n",
    "            while sr - s[left] + 1 > n:  # 窗口长度大于 n\n",
    "                left += 1  # 缩小窗口长度\n",
    "\n",
    "            max_cnt = max(max_cnt, right - left + 1)  # 维护窗口内的最大石子数\n",
    "\n",
    "        return [n - max_cnt, max_move]\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        stones.sort()\n",
    "        N = len(stones)\n",
    "        mn, r = N, 0\n",
    "        for l in range(N):\n",
    "            while r < N - 1 and stones[r + 1] - stones[l] + 1 <= N:\n",
    "                r += 1\n",
    "            \n",
    "            if r - l + 1 == N - 1 and stones[r] - stones[l] + 1 == N - 1:\n",
    "                mn = min(mn, 2)\n",
    "            else:\n",
    "                mn = min(mn, N - (r - l + 1))\n",
    "\n",
    "        return [mn, max(stones[-1] - stones[1], stones[-2] - stones[0]) - N + 2]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        #copy\n",
    "        stones.sort()\n",
    "        n = len(stones)\n",
    "        e1 = stones[-2] -stones[0] -n+2\n",
    "        e2 = stones[-1]-stones[1]-n+2\n",
    "        maxmove = max(e1,e2)\n",
    "        if e1 ==0 or e2 ==0:\n",
    "            return [min(2,maxmove),maxmove]\n",
    "        maxcnt = left = 0\n",
    "        for right ,sr in enumerate(stones):\n",
    "            while sr - stones[left]+1>n:\n",
    "                left += 1\n",
    "            maxcnt = max(maxcnt,right-left+1)\n",
    "        return [n-maxcnt,maxmove]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        stones.sort()\n",
    "        n = len(stones)\n",
    "        if stones[-1] - stones[0] + 1 == n:\n",
    "            return [0, 0]\n",
    "        vmax = max(stones[-2]-stones[0]+1, stones[-1]-stones[1]+1) - (n-1)\n",
    "        left, right = 0, 0\n",
    "        vmin = n\n",
    "        while left < n:\n",
    "            while right < n and stones[right] - stones[left] + 1 <= n:\n",
    "                right += 1\n",
    "            if right - left == n - 1 and stones[right-1] - stones[left] + 1 == n - 1:\n",
    "                vmin = min(vmin, 2)\n",
    "            else:\n",
    "                vmin = min(vmin, n - (right-left))\n",
    "            left += 1\n",
    "        return [vmin, vmax]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, s: List[int]) -> List[int]:\n",
    "        s.sort()\n",
    "        n = len(s)\n",
    "        tot = s[-1] - s[0] + 1 - n\n",
    "        mx = tot - min(s[1] - s[0] - 1, s[-1] - s[-2] - 1)\n",
    "\n",
    "        mn = mx\n",
    "        l = 0\n",
    "        for r in range(n):\n",
    "            while s[r] - s[l] + 1 > n:\n",
    "                l += 1\n",
    "            t = n - (r - l + 1)\n",
    "            if r - l + 1 == n - 1 and s[r] - s[l] + 1 == n - 1:\n",
    "                t = 2\n",
    "            mn = min(mn, t)\n",
    "\n",
    "        return [mn, mx]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        n = len(stones)\n",
    "        stones.sort()\n",
    "        if stones[-1] - stones[0] + 1 ==n:\n",
    "            return [0,0]\n",
    "        \n",
    "        ma = max(stones[-2]- stones[0] + 1, stones[-1] - stones[1] + 1) - (n-1)\n",
    "        mi = n\n",
    "        j = 0\n",
    "        for i in range(n):\n",
    "            while j + 1 < n and stones[j+1] - stones[i] + 1 <= n:\n",
    "                j += 1\n",
    "            if j + 1 - i == n-1 and stones[j] - stones[i] + 1 == n-1:\n",
    "                mi = min(mi,2)\n",
    "            else:\n",
    "                mi = min(mi,n-(j-i+1))\n",
    "        return [mi,ma] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "      stones.sort()\n",
    "      n = len(stones)\n",
    "      \n",
    "      # Calculate max_moves\n",
    "      max_moves = max(stones[-1] - stones[1] - n + 2, stones[-2] - stones[0] - n + 2)\n",
    "      \n",
    "      # Calculate min_moves using sliding window\n",
    "      min_moves = n\n",
    "      j = 0\n",
    "      for i in range(n):\n",
    "          while j < n and stones[j] - stones[i] < n:\n",
    "              j += 1\n",
    "          if j - i == n - 1 and stones[j-1] - stones[i] == n - 2:\n",
    "              min_moves = min(min_moves, 2)\n",
    "          else:\n",
    "              min_moves = min(min_moves, n - (j - i))\n",
    "      \n",
    "      return [min_moves, max_moves]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        s = stones\n",
    "        s.sort()\n",
    "        n = len(s)\n",
    "        e1 = s[-2] - s[0] - n + 2\n",
    "        e2 = s[-1] - s[1] - n + 2\n",
    "        max_move = max(e1, e2)\n",
    "        if e1==0 or e2 == 0:\n",
    "            return [min(2, max_move), max_move]\n",
    "        max_cnt = left = 0\n",
    "        for right, sr in enumerate(s):\n",
    "            while sr - s[left] + 1 > n:\n",
    "                left += 1\n",
    "            max_cnt = max(max_cnt, right - left + 1)\n",
    "        \n",
    "        return [n-max_cnt, max_move]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        stones.sort()\n",
    "        mi = n = len(stones)\n",
    "        mx = max(stones[-1] - stones[1] + 1, stones[-2] - stones[0] + 1) - (n - 1)\n",
    "        i = 0\n",
    "        for j, x in enumerate(stones):\n",
    "            while x - stones[i] + 1 > n:\n",
    "                i += 1\n",
    "            if j - i + 1 == n - 1 and x - stones[i] + 1 == n - 1:\n",
    "                mi = min(mi, 2)\n",
    "            else:\n",
    "                mi = min(mi, n - (j - i + 1))\n",
    "        return [mi, mx]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, s: List[int]) -> List[int]:\n",
    "        s.sort()\n",
    "        n = len(s)\n",
    "        tot = s[-1] - s[0] + 1 - n\n",
    "        mx = tot - min(s[1] - s[0] - 1, s[-1] - s[-2] - 1)\n",
    "\n",
    "        mn = mx\n",
    "        l = 0\n",
    "        for r in range(n):\n",
    "            while s[r] - s[l] + 1 > n:\n",
    "                l += 1\n",
    "            t = n - (r - l + 1)\n",
    "            if r - l + 1 == s[r] - s[l] + 1 == n - 1:\n",
    "                t = 2\n",
    "            mn = min(mn, t)\n",
    "\n",
    "        return [mn, mx]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        s = sorted(stones)\n",
    "        n = len(s)\n",
    "        e1 = s[n-2]-s[0]-1-(n-3)\n",
    "        e2 = s[n-1]-s[1]-1-(n-3)\n",
    "        maxmove = max(e1,e2)\n",
    "        if e1==0 or e2==0:\n",
    "            return [min(2,maxmove),maxmove]\n",
    "        \n",
    "        maxcnt, left = 0, 0\n",
    "        for right, st in enumerate(s):\n",
    "            while st-s[left]+1>n:\n",
    "                left += 1\n",
    "            maxcnt = max(maxcnt,right-left+1)\n",
    "        return [n-maxcnt, maxmove]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        n = len(stones)\n",
    "        stones.sort()\n",
    "        if stones[-1] - stones[0] + 1 == n:\n",
    "            return [0, 0]\n",
    "        ma = max(stones[-2] - stones[0] + 1, stones[-1] - stones[1] + 1) - (n - 1)\n",
    "        mi = n\n",
    "        j = 0\n",
    "        for i in range(n):\n",
    "            while j + 1 < n and stones[j + 1] - stones[i] + 1 <= n:\n",
    "                j += 1\n",
    "            if j - i + 1 == n - 1 and stones[j] - stones[i] + 1 == n - 1:\n",
    "                mi = min(mi, 2)\n",
    "            else:\n",
    "                mi = min(mi, n - (j - i + 1))\n",
    "        return [mi, ma]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        stones.sort()\n",
    "        n=len(stones)\n",
    "        if stones[-1] - stones[0] + 1 == n:\n",
    "            return [0, 0]\n",
    "        ma = max(stones[-2] - stones[0] + 1, stones[-1] - stones[1] + 1) - (n - 1)\n",
    "        mi= n\n",
    "        j = 0\n",
    "        for i in range(n):\n",
    "            while j + 1 < n and stones[j + 1] - stones[i] + 1 <= n:\n",
    "                j += 1\n",
    "            if j - i + 1 == n - 1 and stones[j] - stones[i] + 1 == n - 1:\n",
    "                mi = min(mi, 2)\n",
    "            else:\n",
    "                mi = min(mi, n - (j - i + 1))\n",
    "        return [mi, ma]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        n = len(stones)\n",
    "        stones.sort()\n",
    "\n",
    "        if stones[n - 1] - stones[0] + 1 == n:\n",
    "            return [0, 0]\n",
    "\n",
    "        ma = max(stones[-2] - stones[0], stones[-1] - stones[1]) + 1 - (n - 1)\n",
    "\n",
    "        mi = n\n",
    "        j = 0\n",
    "        for i in range(n):\n",
    "            while j + 1 < n and stones[j + 1] - stones[i] + 1 <= n:\n",
    "                j += 1\n",
    "\n",
    "            if j - i + 1 == n - 1 and stones[j] - stones[i] + 1 == n - 1:\n",
    "                mi = min(mi, 2)\n",
    "\n",
    "            else:\n",
    "                mi = min(mi, n - (j - i + 1))\n",
    "\n",
    "        return [mi, ma]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        n = len(stones)\n",
    "        stones.sort()\n",
    "        if stones[-1] - stones[0] +1 == n:\n",
    "            return [0, 0]\n",
    "        ma = max(stones[-2] - stones[0] + 1, stones[-1] - stones[1] + 1) - (n - 1)\n",
    "        mi = n\n",
    "        j = 0\n",
    "        for i in range(n):\n",
    "            while j + 1 < n and stones[j + 1] - stones[i] + 1 <= n:\n",
    "                j += 1\n",
    "            if j - i + 1 == n - 1 and stones[j] - stones[i] + 1 == n - 1:\n",
    "                mi = min(mi, 2)\n",
    "            else:\n",
    "                mi = min(mi, n - (j -i + 1))\n",
    "        return [mi, ma]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, s: List[int]) -> List[int]:\n",
    "        s.sort()\n",
    "        n = len(s)\n",
    "        e1 = s[-2] - s[0] - n + 2\n",
    "        e2 = s[-1] - s[1] - n + 2  # 计算空位\n",
    "        max_move = max(e1, e2)\n",
    "        if e1 == 0 or e2 == 0:  # 特殊情况：没有空位\n",
    "            return [min(2, max_move), max_move]\n",
    "        max_cnt = left = 0\n",
    "        for right, sr in enumerate(s):  # 滑动窗口：枚举右端点所在石子\n",
    "            while sr - s[left] + 1 > n:  # 窗口长度大于 n\n",
    "                left += 1  # 缩小窗口长度\n",
    "            max_cnt = max(max_cnt, right - left + 1)  # 维护窗口内的最大石子数\n",
    "        return [n - max_cnt, max_move]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        n = len(stones)\n",
    "        stones.sort()\n",
    "        if stones[-1] - stones[0] + 1 == n:\n",
    "            return [0, 0]\n",
    "        ma = max(stones[-2] - stones[0] + 1, stones[-1] - stones[1] + 1) - (n - 1)\n",
    "        mi = n\n",
    "        j = 0\n",
    "        for i in range(n):\n",
    "            while j + 1 < n and stones[j + 1] - stones[i] + 1 <= n:\n",
    "                j += 1\n",
    "            if j - i + 1 == n - 1 and stones[j] - stones[i] + 1 == n - 1:\n",
    "                mi = min(mi, 2)\n",
    "            else:\n",
    "                mi = min(mi, n - (j - i + 1))\n",
    "        return [mi, ma]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        stones.sort()\n",
    "        n = len(stones)\n",
    "        max_gap = max(stones[-1] - stones[1] - (n-2), stones[-2] - stones[0] - (n-2))\n",
    "        min_gap = float('inf')\n",
    "        j = 0\n",
    "\n",
    "        for i in range(n):\n",
    "            while j < n and stones[j] - stones[i] + 1 <= n:\n",
    "                j += 1\n",
    "            cost = n - (j - i)\n",
    "            if j - i == n - 1 and stones[j - 1] - stones[i] + 1 == n - 1:\n",
    "                cost = 2\n",
    "            min_gap = min(min_gap, cost)\n",
    "        return [min_gap, max_gap]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        stones.sort()\n",
    "        n, mn, end = len(stones), 1, 0\n",
    "        mx = max(stones[-2] - stones[0], stones[-1] - stones[1]) + 2 - n\n",
    "        for i,v in enumerate(stones):\n",
    "            while end < n and stones[end]-v < n: end += 1\n",
    "            mn = max(mn, end - i)\n",
    "        if mn==n-1 and ((stones[n-2]-stones[0] == n-2 and stones[n-1] - stones[n-2] > 2) or (stones[n-1]-stones[1] == n-2 and stones[1] - stones[0] > 2)): mn -= 1\n",
    "        return [n - mn,mx]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "      n=len(stones)\n",
    "      stones.sort()\n",
    "      # 计算最大play次数\n",
    "      # 每次都让同一侧的石子去跳，这样的话，除了第一次起跳，剩下的都只可能让区间的大小-1，最终形成一个连续区间。假设每次都让最左侧的石头跳，那么结果为stones[-1]-stones[1]-1-(n-3)=stones[-1]-stones[1]-n+2,因此结果为max(stones[-1]-stones[1]-n+2,stones[-2]-stones[0]-n+2)\n",
    "      # 计算最小play次数\n",
    "      # 维护一个大小为n的窗口。首先讨论特殊情况，如果stones[1]到stones[-1]或stones[0]到stones[-2]已经连续，那么需要最小要跳动的次数为2。不然的话，最小跳动次数为min(n-max窗口中石子个数)\n",
    "      max1=stones[-1]-stones[1]-n+2\n",
    "      max2=stones[-2]-stones[0]-n+2\n",
    "      max_ret=max(max1,max2)\n",
    "      if max1==0 or max2==0:\n",
    "        return [min(2,max_ret),max_ret]\n",
    "      max_window=0\n",
    "      l=0\n",
    "      for r,r_bound in enumerate(stones):\n",
    "        # 窗口长度大于n\n",
    "        while r_bound-stones[l]+1>n:\n",
    "          l+=1\n",
    "        # 使得窗口长度小于等于n\n",
    "        max_window=max(max_window,r-l+1)\n",
    "      return [n-max_window,max_ret]\n",
    "\n",
    "      "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n",
    "        # 最小的移动次数等于 数组长度 减去最长连续子串的长度，子串可以有一个空位\n",
    "        # 最大的移动次数，向一个位置进行靠拢\n",
    "    # 上面这玩意写的乱七八糟\n",
    "        n = len(stones)\n",
    "        stones.sort()\n",
    "        if stones[-1] - stones[0] + 1 == n:\n",
    "            return [0,0]\n",
    "        ma = max(stones[-2] - stones[0] + 1,stones[-1] - stones[1] + 1) -(n - 1)\n",
    "        mi =  n\n",
    "        j = 0\n",
    "        for i in range(n):\n",
    "            while j + 1 < n and stones[j + 1] - stones[i] + 1 <= n:\n",
    "                j += 1\n",
    "            if j -i + 1 == n - 1 and stones[j] - stones[i] + 1 == n -1:\n",
    "                mi = min(mi,2)\n",
    "            else:\n",
    "                mi = min(mi,n-(j-i+1))\n",
    "        return [mi,ma]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        x, y, z = sorted([a, b, c])\n",
    "        res = [2, z - x - 2]\n",
    "        if ((z - y) == 1 and (y - x) == 1):\n",
    "            res[0] = 0\n",
    "        elif ((z - y) <= 2 or (y - x) <= 2):\n",
    "            res[0] = 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a,b,c = sorted([a,b,c])\n",
    "        max = c-b-1 + b-a-1\n",
    "        d1 = b-a\n",
    "        d2 = c-b\n",
    "        if d1 + d2 ==2:\n",
    "            min = 0\n",
    "        elif (d1 <= 2) or (d2 <= 2):\n",
    "            min = 1\n",
    "        else:\n",
    "            min = 2\n",
    "        return [min,max]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "\n",
    "        tmp = [a, b, c]\n",
    "        tmp.sort()\n",
    "        a,b,c = tmp\n",
    "\n",
    "        max_ = c - a - 2 # (b - a) + (c - b) - 2 = c - a - 2\n",
    "\n",
    "        if max_ == 0:\n",
    "            return [0, 0]\n",
    "\n",
    "        \n",
    "        if b - a == 1 or c - b == 1:\n",
    "            min_ = 1\n",
    "        elif b - a == 2 or c - b == 2:\n",
    "            min_ = 1\n",
    "        else:\n",
    "            min_ = 2\n",
    "\n",
    "        return [min_, max_]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        ans = [-1, -1]\n",
    "        arr = [a, b, c]\n",
    "        arr.sort()\n",
    "        ans[-1] = arr[-1] - arr[0] - 2\n",
    "        if arr[-1] - arr[0] == 2:\n",
    "            ans[0] = 0\n",
    "        elif 1 <= (arr[-1] - arr[1]) <= 2 or 1 <= (arr[1] - arr[0]) <= 2:\n",
    "            ans[0] = 1\n",
    "        else:\n",
    "            ans[0] = 2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a, b, c = sorted((a, b, c))\n",
    "        return [0 if c - a == 2 else\n",
    "                1 if b - a <= 2 or c - b <= 2 else\n",
    "                2,\n",
    "                c - a - 2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a,b,c = min(a,b,c),a+b+c-max(a,b,c)-min(a,b,c),max(a,b,c)\n",
    "        if b-a == 1:\n",
    "            if c-b == 1:\n",
    "                return [0,0]\n",
    "            else:\n",
    "                return [1,c-b-1]\n",
    "        elif b-a == 2:\n",
    "            if c-b == 1:\n",
    "                return [1,1]\n",
    "            else:\n",
    "                return [1,c-b]\n",
    "        else:\n",
    "            if c-b == 1:\n",
    "                return [1,b-a-1]\n",
    "            elif c-b == 2:\n",
    "                return [1,b-a]\n",
    "            else:\n",
    "                return [2,c-a-2]\n",
    "    \n",
    "         "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        l1 = sorted([a,b,c])\n",
    "        x = l1[0]\n",
    "        y = l1[1]\n",
    "        z = l1[2]\n",
    "\n",
    "        res = [2,z-x-2]\n",
    "        if ((z-y)==1 and (y-x)==1):\n",
    "            res[0] = 0\n",
    "        elif ((z-y)<=2 or (y-x)<=2):\n",
    "            res[0]=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        nums = [a,b,c]\n",
    "        nums.sort()\n",
    "        a,b,c = nums[0],nums[1],nums[2]\n",
    "        ab = b-a-1\n",
    "        bc = c-b-1\n",
    "        if ab==0 and bc==0:\n",
    "            mi = 0\n",
    "            ma = 0\n",
    "        elif ab == 0 or bc ==0:\n",
    "            mi = 1\n",
    "            ma = max(ab,bc)\n",
    "        elif ab==1 or bc == 1:\n",
    "            mi=1\n",
    "            ma = ab+bc\n",
    "        else:\n",
    "            mi = 2\n",
    "            ma = ab+bc\n",
    "        return [mi,ma]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        sort_list = sorted([a, b, c])\n",
    "        a, b, c = sort_list[0], sort_list[1], sort_list[2]\n",
    "        diffs = [b - a, c - b]\n",
    "        if diffs[0] == 1 and diffs[1] == 1:\n",
    "            min_steps = 0\n",
    "        elif diffs[0] <= 2 or diffs[1] <= 2:\n",
    "            min_steps = 1\n",
    "        else:\n",
    "            min_steps = 2\n",
    "        max_steps = sum(diffs) - 2\n",
    "        return [min_steps, max_steps]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        min_num = min(a,b,c)\n",
    "        max_num = max(a,b,c)\n",
    "        resmax = max_num - min_num - 2\n",
    "        resmin = 2\n",
    "        if resmax == 0:\n",
    "            resmin = 0\n",
    "        else:\n",
    "            if abs(a-b) <= 2 or abs(b-c) <= 2 or abs(a-c) <= 2:\n",
    "                resmin = 1\n",
    "        \n",
    "        return [resmin,resmax]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a, b, c = sorted((a, b, c))\n",
    "        return [0 if c-a==2 else \n",
    "                1 if b-a<=2 or c-b <= 2 else \n",
    "                2,\n",
    "                 c-a-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        def minMonves(a, b, c):\n",
    "            a, b, c = (sorted([a, b, c]))\n",
    "            maxM = max(b-a, c-b)\n",
    "            minM = min(b-a, c-b)\n",
    "            if minM == 1 and maxM == 1:\n",
    "                return 0\n",
    "            elif minM <= 2:\n",
    "                return 1\n",
    "            else:\n",
    "                return 2\n",
    "        \n",
    "        max_m = max(a, b, c) - min(a, b, c) - 2\n",
    "        min_m = minMonves(a, b, c)\n",
    "\n",
    "        return [min_m, max_m]\n",
    "            \n",
    "            \n",
    "\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        if a > b:\n",
    "            a, b = b, a\n",
    "        if b > c:\n",
    "            b, c = c, b\n",
    "        if a > b:\n",
    "            a, b = b, a \n",
    "\n",
    "        if c > b + 2 and b > a + 2:\n",
    "            minimum_moves = 2\n",
    "        elif a + 1 == b and b + 1 == c:\n",
    "            minimum_moves = 0\n",
    "        else:\n",
    "            minimum_moves = 1\n",
    "        maximum_moves = c - a - 2\n",
    "        return [minimum_moves, maximum_moves]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        ls = []\n",
    "        ls.append(a)\n",
    "        ls.append(b)\n",
    "        ls.append(c)\n",
    "        ls.sort()\n",
    "        a, b, c = ls[0], ls[1], ls[2]\n",
    "        ans1, ans2 = 2, c - a - 2\n",
    "        d1, d2 = b - a, c - b\n",
    "        if d1 == 1: ans1 -= 1\n",
    "        if d2 == 1: ans1 -= 1\n",
    "        if d1 == 2 or d2 == 2: ans1 = 1\n",
    "        ans = []\n",
    "        ans.append(ans1)\n",
    "        ans.append(ans2)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a, b, c = sorted([a, b, c])\n",
    "        if c - a == 2: minr = 0\n",
    "        elif b - a <= 2 or c - b <= 2: minr = 1\n",
    "        else: minr = 2\n",
    "        return [minr, c - a - 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        tmp = sorted([a,b,c])\n",
    "        valtmp1, valtmp2 = tmp[1] - tmp[0], tmp[2] - tmp[1]\n",
    "        minval = 2\n",
    "        if valtmp1 == 1 and valtmp2 == 1 :\n",
    "            return [0,0]\n",
    "        if valtmp1 < 3 or valtmp2 < 3  :\n",
    "            minval = 1\n",
    "        return [minval,valtmp1 + valtmp2 - 2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        x, y, z = sorted([a, b, c])\n",
    "        res = [2, z - x - 2]\n",
    "        if (z - y) == 1 and (y - x) == 1:\n",
    "            res[0] = 0\n",
    "        elif (z - y) <= 2 or (y - x) <= 2:\n",
    "            res[0] = 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a,b,c=sorted([a,b,c])\n",
    "        if c-b==1 and b-a==1:\n",
    "            return 0,0\n",
    "        maxNum=c-b-1+b-a-1\n",
    "        minNum=2 if c-b>2 and b-a>2 else 1\n",
    "        return minNum,maxNum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        A=min(a,b,c)\n",
    "        C=max(a,b,c)\n",
    "        if a!=A and a!=C:\n",
    "            B=a\n",
    "        elif b!=A and b!=C:\n",
    "            B=b\n",
    "        else: B=c\n",
    "        if B-A==1 and C-B==1 :\n",
    "            return([0,0])\n",
    "        elif B-A<=2 or C-B<=2:\n",
    "            return([1,C-A-2])\n",
    "        else :return([2,C-A-2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        [a, b, c] = sorted([a, b, c])\n",
    "        maximum_moves = c - a - 2\n",
    "        if a + 1 == b and b + 1 == c:\n",
    "            minimum_moves = 0\n",
    "        elif b - a <= 2 or c - b <= 2:\n",
    "            minimum_moves = 1\n",
    "        else:\n",
    "            minimum_moves = 2\n",
    "        return [minimum_moves, maximum_moves]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a, b, c = sorted((a, b, c))\n",
    "        return [0 if c - a == 2 else\n",
    "                1 if b - a <= 2 or c - b <= 2 else\n",
    "                2,\n",
    "                c - a - 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "\n",
    "        nums = [a,b,c]\n",
    "        nums.sort()\n",
    "\n",
    "        a,b,c = nums\n",
    "\n",
    "\n",
    "        return [min(b-a-1, 1)+min(c-b-1, 1) if not (b-a == 2 or c-b == 2) else 1, b-a-1+c-b-1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        data=[a,b,c]\n",
    "        data.sort()\n",
    "        a,b=data[1]-data[0]-1,data[2]-data[1]-1\n",
    "        if (data[2]-data[1])==1 and (data[1]-data[0])==1:\n",
    "            ans1=0\n",
    "        elif (data[2]-data[1])<=2 or (data[1]-data[0])<=2:\n",
    "            ans1=1\n",
    "        else:\n",
    "            ans1=2\n",
    "        ans2=a+b\n",
    "        return [ans1,ans2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "      a, b, c = sorted((a, b, c))\n",
    "      if c-a == 2: return [0, c-a-2]\n",
    "      elif c-b <= 2 or b-a <= 2: return [1, c-a-2]\n",
    "      else: return [2, c-a-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a, b, c = sorted([a, b, c])\n",
    "        if b - a == 1:\n",
    "            if c - b == 1:  return [0, 0]\n",
    "            else:   minVal = 1\n",
    "        elif b - a == 2:    minVal = 1\n",
    "        elif c - b <= 2:    minVal = 1\n",
    "        else:   minVal = 2\n",
    "        \n",
    "        if b - a > c - b:\n",
    "            maxVal = b - a - 1\n",
    "            a = b - 1\n",
    "        else:\n",
    "            maxVal = c - b - 1\n",
    "            c = b + 1\n",
    "\n",
    "        if b - a == 1:\n",
    "            if c - b == 1:  return [minVal, maxVal]\n",
    "            else:   return [minVal, maxVal + c - b - 1]\n",
    "        elif c - b == 1:    return [minVal, maxVal + b - a - 1]\n",
    "        else:   return [minVal, maxVal]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        x, y, z = sorted([a, b, c])\n",
    "        res = [2, z - x - 2]\n",
    "        if ((z - y) == 1 and (y - x) == 1):\n",
    "            res[0] = 0\n",
    "        elif ((z - y) <= 2 or (y - x) <= 2):\n",
    "            res[0] = 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        x, y, z = sorted([a, b, c])\n",
    "        result = [2, z-x-2]\n",
    "        if y-x == 1 and z-y==1:\n",
    "            result[0] = 0\n",
    "        elif y-x <= 2 or z-y <= 2:\n",
    "            result[0] = 1\n",
    "        return result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        x = min(a,b,c)\n",
    "        z = max(a,b,c)\n",
    "        y = a + b + c - x - z\n",
    "        space1 = y - x - 1\n",
    "        space2 = z - y - 1\n",
    "        if space1 >= 2 and space2 >= 2:\n",
    "            return [2,space1 + space2]\n",
    "        elif space1*space2 != 0:\n",
    "            return [1,space1+space2]\n",
    "        elif space1 == 0 and space2 == 0:\n",
    "            return [0,0]\n",
    "        else:\n",
    "            return [1,max(space1,space2)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a, b ,c = sorted([a,b,c])\n",
    "        #最小\n",
    "        if(a+1 == b == c-1):\n",
    "            min_cnt = 0\n",
    "        elif(a+1 == b):\n",
    "            min_cnt = 1\n",
    "        elif(b == c-1):\n",
    "            min_cnt = 1\n",
    "        elif(a+2 == b or b+2 == c):\n",
    "            min_cnt = 1\n",
    "        else:\n",
    "            min_cnt = 2\n",
    "        #最大\n",
    "        max_cnt = max(b-a-1+c-b-1, c-b-1+b-a-1)\n",
    "        return [min_cnt, max_cnt]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        t = [a,b,c]\n",
    "        t.sort()\n",
    "        a,b,c = t[0],t[1],t[2]\n",
    "        ma = b-a+c-b-2\n",
    "        if b-a==1 and c-b==1:\n",
    "            mi = 0\n",
    "        elif b-a==1 or c-b==1 or b-a==2 or c-b==2:\n",
    "            mi = 1\n",
    "        else:\n",
    "            mi = 2\n",
    "        return [mi,ma]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        x = min([a,b,c])\n",
    "        z = max([a,b,c])\n",
    "        y = a + b + c - x - z\n",
    "        mini = 2\n",
    "        if z-y == 1:   mini -= 1\n",
    "        if y-x == 1:   mini -= 1\n",
    "        if z-y == 2 or y-x == 2:    mini = 1\n",
    "\n",
    "\n",
    "\n",
    "        maxi = z-y + y-x - 2\n",
    "        return [mini, maxi]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        l = sorted((a, b, c))\n",
    "        dis1 = l[1] - l[0]\n",
    "        dis2 = l[2] - l[1]\n",
    "        if dis1 == 2 or dis2 == 2:\n",
    "            mn = 1\n",
    "        else:\n",
    "            mn = (dis1 > 1) + (dis2 > 1)\n",
    "        mx = dis1 + dis2 - 2\n",
    "        return [mn, mx]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        #copy 0x3\n",
    "        a,b,c  = sorted((a,b,c))\n",
    "        return [0 if c-a ==2 else 1 if b-a<=2 or c-b<=2 else 2,c-a-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        ans=sorted([a,b,c])\n",
    "        if (ans[0]==ans[1]+1 and ans[1]==ans[2]+1) or (ans[0]==ans[1]-1 and ans[1]==ans[2]-1):\n",
    "            return [0,0]\n",
    "        lma=abs(ans[0]-ans[1])-1\n",
    "        if lma==0:\n",
    "            lmi=0\n",
    "        else:\n",
    "            lmi=1\n",
    "        rma=abs(ans[2]-ans[1])-1\n",
    "        if rma==0:\n",
    "            rmi=0\n",
    "        else:\n",
    "            rmi=1\n",
    "        if (abs(ans[0]-ans[1])==2) or (abs(ans[2]-ans[1])==2):\n",
    "            return [1,lma+rma]\n",
    "        return [rmi+lmi,rma+lma]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        _a, _b, _c = sorted([a, b, c])\n",
    "        minimum_moves = 2\n",
    "        if _c == _a+2:\n",
    "            minimum_moves = 0\n",
    "        elif _c == _b+1 or _b == _a+1 or _c == _b+2 or _b == _a+2:\n",
    "            minimum_moves = 1\n",
    "        \n",
    "        maximum_moves = _c-_a-2\n",
    "        return [minimum_moves, maximum_moves]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        x, y, z = sorted([a, b, c])\n",
    "        res = [2, z - x - 2]\n",
    "        if ((z - y) == 1 and (y - x) == 1):\n",
    "            res[0] = 0\n",
    "        elif ((z - y) <= 2 or (y - x) <= 2):\n",
    "            res[0] = 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        m, n = max(a,b,c), min(a,b,c)\n",
    "        max_stpe = m - n - 2\n",
    "        l = a + b + c - m - n\n",
    "        if m - l < 3 or l - n < 3:\n",
    "            return [min(1, max_stpe), max_stpe]\n",
    "        return [2, max_stpe]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        sort_list = [a, b, c]\n",
    "        sort_list.sort()\n",
    "        a, b, c = sort_list[0], sort_list[1], sort_list[2]\n",
    "        if b - a == 1 and c - b == 1:\n",
    "            minimum_moves = 0\n",
    "        elif (b - a == 2 or c - b == 2) or (b - a == 1 or c - b == 1):\n",
    "            minimum_moves = 1\n",
    "        else:\n",
    "            minimum_moves = 2\n",
    "        maximum_moves = c - a - 2\n",
    "        return [minimum_moves, maximum_moves]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        M=max(a,b,c)-min(a,b,c)-2\n",
    "        if M==0:m=0\n",
    "        elif (abs(a-b)<=2 or abs(a-c)<=2 or abs(b-c)<=2):m=1\n",
    "        else:m=2\n",
    "        return [m,M]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a,b,c = sorted([a,b,c])\n",
    "        abrel = False\n",
    "        bcrel = False\n",
    "        count = 0\n",
    "        if b-a == 1:\n",
    "            abrel = True\n",
    "        if c-b == 1:\n",
    "            bcrel = True\n",
    "        if abrel and bcrel:\n",
    "            return [0,0]\n",
    "        elif abrel:\n",
    "            return [1, c-b-1]\n",
    "        elif bcrel:\n",
    "            return [1, b-a-1]\n",
    "        else:\n",
    "            if c-b==2 or b-a==2:\n",
    "                return [1, c-a-2]\n",
    "            else:\n",
    "                return [2, c-a-2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        x = min([a,b,c])\n",
    "        z = max([a,b,c])\n",
    "        y = a + b + c - x - z\n",
    "        mini = 2\n",
    "        if z-y == 1:   mini -= 1\n",
    "        if y-x == 1:   mini -= 1\n",
    "        if z-y == 2 or y-x == 2:    mini = 1\n",
    "\n",
    "\n",
    "\n",
    "        maxi = z-y + y-x - 2\n",
    "        return [mini, maxi]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a, b, c = sorted([a, b, c])\n",
    "        low, high = 0, c - a - 2\n",
    "        if c - b == 1 and b - a == 1:\n",
    "            low = 0\n",
    "        elif (c - b == 1 and b - a != 1) or (b - a == 1 and c - b != 1) or (b - a == 2) or (c - b == 2):\n",
    "            low = 1\n",
    "        else:\n",
    "            low = 2\n",
    "        return [low, high]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a, b ,c = sorted([a,b,c])\n",
    "        #最小\n",
    "        if(a+1 == b == c-1):\n",
    "            min_cnt = 0\n",
    "        elif(a+1 == b):\n",
    "            min_cnt = 1\n",
    "        elif(b == c-1):\n",
    "            min_cnt = 1\n",
    "        elif(a+2 == b or b+2 == c):\n",
    "            min_cnt = 1\n",
    "        else:\n",
    "            min_cnt = 2\n",
    "        #最大\n",
    "        max_cnt = max(b-a-1+c-b-1, c-b-1+b-a-1)\n",
    "        return [min_cnt, max_cnt]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        nums = sorted([a, b, c])\n",
    "        a, b, c = nums[0], nums[1], nums[2]\n",
    "        maxval = (b-a-1) + (c-b-1)\n",
    "        if a == b-1 and b == c-1:\n",
    "            minval = 0\n",
    "        elif a == b-1 or b == c-1:\n",
    "            minval = 1\n",
    "        else:\n",
    "            if b-a == 2 or c-b == 2:\n",
    "                minval = 1\n",
    "            else:\n",
    "                minval = 2\n",
    "        return [minval, maxval]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        x, y, z = sorted([a, b, c])\n",
    "        res = [2, z - x - 2]\n",
    "        if ((z - y) == 1 and (y - x) == 1):\n",
    "            res[0] = 0\n",
    "        elif ((z - y) <= 2 or (y - x) <= 2):\n",
    "            res[0] = 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a, b, c = sorted([a, b, c])\n",
    "        print(a, b, c)\n",
    "\n",
    "        mins, maxs = 0, 0\n",
    "        if a + 2 == b or b + 2 == c:\n",
    "            mins = 1\n",
    "        else:\n",
    "            mins += 1 if a + 1 < b else 0\n",
    "            mins += 1 if b + 1 < c else 0\n",
    "        maxs = c - a - 2\n",
    "        return [mins, maxs]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        l = [a, b, c]\n",
    "        l.sort()\n",
    "        x, y = abs(l[0] - l[1]), abs(l[1] - l[2])\n",
    "        ans = [2, 0]\n",
    "        if (x == 1)and (y == 1):\n",
    "            ans[0] = 0\n",
    "        elif x <= 2 or y <= 2:\n",
    "            ans[0] = 1\n",
    "        ans[1] = x + y - 2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a, b ,c = sorted([a,b,c])\n",
    "        #最小\n",
    "        if(a+1 == b == c-1):\n",
    "            min_cnt = 0\n",
    "        elif(a+1 == b):\n",
    "            min_cnt = 1\n",
    "        elif(b == c-1):\n",
    "            min_cnt = 1\n",
    "        elif(a+2 == b or b+2 == c):\n",
    "            min_cnt = 1\n",
    "        else:\n",
    "            min_cnt = 2\n",
    "        #最大\n",
    "        max_cnt = c-a-2\n",
    "        return [min_cnt, max_cnt]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a, b ,c = sorted([a,b,c])\n",
    "        #最小\n",
    "        if(a+1 == b == c-1):\n",
    "            min_cnt = 0\n",
    "        elif(a+1 == b):\n",
    "            min_cnt = 1\n",
    "        elif(b == c-1):\n",
    "            min_cnt = 1\n",
    "        elif(a+2 == b or b+2 == c):\n",
    "            min_cnt = 1\n",
    "        else:\n",
    "            min_cnt = 2\n",
    "        #最大\n",
    "        max_cnt = c-a-2\n",
    "        return [min_cnt, max_cnt]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        stones = sorted([a, b, c])\n",
    "        minMoves, maxMoves = 0, stones[2] - stones[0] - 2\n",
    "        if stones[2] - stones[1] == 1 and stones[1] - stones[0] == 1:\n",
    "            return [0, 0]\n",
    "\n",
    "        if stones[2] - stones[1] <= 2 or stones[1] - stones[0] <= 2:\n",
    "            minMoves = 1\n",
    "        elif stones[2] - stones[0] > 2:\n",
    "            minMoves = 2\n",
    "        \n",
    "        return [minMoves, maxMoves]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        lst = [a, b, c]\n",
    "        lst.sort()\n",
    "        a, b, c = lst\n",
    "        if a + 1 == b and b + 1 == c:\n",
    "            return [0,0]\n",
    "        elif a + 1 == b or b + 1 == c:\n",
    "            return [1, max(b - a, c - b) - 1]\n",
    "        elif a + 2 == b or b + 2 == c:\n",
    "            return [1, c - b - 1 + b - a - 1]\n",
    "        else:\n",
    "            return [2, c - b - 1 + b - a - 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        l = [a, b, c]\n",
    "        l.sort()\n",
    "        d1, d2 = l[1] - l[0] - 1, l[2] - l[1] - 1\n",
    "        if d1 == 0 and d2 == 0:\n",
    "            return [0, 0]\n",
    "        if d1 <= 1 or d2 <= 1:\n",
    "            return [1, d1 + d2]\n",
    "        return [2, d1 + d2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a,b,c = sorted([a,b,c])\n",
    "        minA = 0 if b-a==1 else 1\n",
    "        minB = 0 if c-b==1 else 1\n",
    "        maxA = b-a-1 if b-a>1 else 0\n",
    "        maxB = c-b-1 if c-b>1 else 0\n",
    "        if c-b==2 or b-a == 2:\n",
    "            minA = 1\n",
    "            minB = 0 \n",
    "        return [minA+minB,maxA+maxB]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        x, y, z = sorted([a,b,c])\n",
    "        aa, bb = y - x, z - y\n",
    "        if aa == 1 and bb == 1:\n",
    "            mi = 0\n",
    "        elif aa == 1 or bb == 1:\n",
    "            mi = 1\n",
    "        elif aa == 2 or bb == 2:\n",
    "            mi = 1\n",
    "        else:\n",
    "            mi = 2\n",
    "        ma = (aa - 1) + (bb- 1)\n",
    "        return [mi,ma]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        a, b, c = sorted([a, b, c])\n",
    "        if b - a == 1:\n",
    "            if c - b == 1:  return [0, 0]\n",
    "            else:   minVal = 1\n",
    "        elif b - a == 2:    minVal = 1\n",
    "        elif c - b <= 2:    minVal = 1\n",
    "        else:   minVal = 2\n",
    "        \n",
    "        if b - a > c - b:\n",
    "            maxVal = b - a - 1\n",
    "            a = b - 1\n",
    "        else:\n",
    "            maxVal = c - b - 1\n",
    "            c = b + 1\n",
    "\n",
    "        if b - a == 1:\n",
    "            if c - b == 1:  return [minVal, maxVal]\n",
    "            else:   return [minVal, maxVal + c - b - 1]\n",
    "        elif c - b == 1:    return [minVal, maxVal + b - a - 1]\n",
    "        else:   return [minVal, maxVal]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        x = min(a,b,c)\n",
    "        z = max(a,b,c)\n",
    "        space1 = a + b + c - x - z - x - 1\n",
    "        space2 = z - (a + b + c - x - z) - 1\n",
    "        if space1 >= 2 and space2 >= 2:\n",
    "            return [2,space1 + space2]\n",
    "        elif space1*space2 != 0:\n",
    "            return [1,space1+space2]\n",
    "        elif space1 == 0 and space2 == 0:\n",
    "            return [0,0]\n",
    "        else:\n",
    "            return [1,max(space1,space2)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        x = min(a,b,c)\n",
    "        z = max(a,b,c)\n",
    "        y = a + b + c - x - z\n",
    "        space1 = y - x - 1\n",
    "        space2 = z - y - 1\n",
    "        if space1 >= 2 and space2 >= 2:\n",
    "            return [2,space1 + space2]\n",
    "        elif space1*space2 != 0:\n",
    "            return [1,space1+space2]\n",
    "        elif space1 == 0 and space2 == 0:\n",
    "            return [0,0]\n",
    "        else:\n",
    "            return [1,max(space1,space2)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        ret = [0,0]\n",
    "        thing = [a,b,c]\n",
    "        thing.sort()\n",
    "        ret[1] = thing[1]-thing[0]-1+thing[2]-thing[1]-1\n",
    "        if(ret[1] == 0):\n",
    "            ret[0] = 0\n",
    "        elif(thing[0] + 1 == thing[1] or \n",
    "        thing[1] + 1 == thing[2] or \n",
    "        thing[1] - thing[0] == 2 or \n",
    "        thing[2] - thing[1] == 2):\n",
    "            ret[0] = 1\n",
    "        else:\n",
    "            ret[0] = 2\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        x, y, z = sorted([a, b, c])\n",
    "        res = [2, z - x - 2]\n",
    "        if ((z - y) == 1 and (y - x) == 1):\n",
    "            res[0] = 0\n",
    "        elif ((z - y) <= 2 or (y - x) <= 2):\n",
    "            res[0] = 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\r\n",
    "        a, b, c = sorted([a, b, c])\r\n",
    "        return [1 if b - a == 2 or c - b == 2 else (b - a > 1) + (c - b > 1), (b - a - 1) + (c - b - 1)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\r\n",
    "        a, b, c = sorted([a, b, c])\r\n",
    "        return [0 if c - a == 2 else 1 if b - a <= 2 or c - b <= 2 else 2, c - a - 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n",
    "        t=[a, b, c]\n",
    "        t.sort()\n",
    "        near1=t[1]-t[0]==1\n",
    "        near2=t[2]-t[1]==1\n",
    "        if near1 and near2:\n",
    "            mi=0\n",
    "        elif near1:\n",
    "            mi=1\n",
    "        elif near2:\n",
    "            mi=1\n",
    "        elif t[0]+2==t[1]:\n",
    "            mi=1\n",
    "        elif t[1]+2==t[2]:\n",
    "            mi=1\n",
    "        else:\n",
    "            mi=2\n",
    "        ma=t[2]-t[0]-2\n",
    "        return [mi,ma]\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
